package com.weishi.project.api.controller;

import com.alibaba.fastjson.JSONObject;
import com.weishi.framework.web.controller.BaseController;
import com.weishi.framework.web.domain.AjaxResult;
import com.weishi.project.api.dto.DynamometerRankingDTO;
import com.weishi.project.api.vo.*;
import com.weishi.project.sport.movement.service.MovementService;
import com.weishi.project.training.domain.*;
import com.weishi.project.training.service.*;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import net.sf.json.JSONArray;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.ArrayList;
import java.util.List;
import java.util.logging.Logger;

@RestController
@RequestMapping("/app/pk")
@Api(value = "PK", description = "PK页面")
public class ApiPKController extends BaseController {

    @Autowired
    private ISportsmanService sportsmanService;

    @Autowired
    private ISportsmanPhysicalQualityService sportsmanPhysicalQualityService;

    /**
     * 运动模块接口
     */
    @Autowired
    private MovementService movementService;

    /**
     * 训练方案接口
     */
    @Autowired
    private ISchemeService schemeService;

    /**
     * 训练方案子表接口
     */
    @Autowired
    private ISchemeDetailsService schemeDetailsService;

    /**
     * 测功仪接口
     */
    @Autowired
    private IDynamometerService dynamometerService;

    /**
     * 赛后数据表接口
     */
    @Autowired
    private IRaceDataService raceDataService;

    /**
     * 船速仪 接口
     */
    @Autowired
    private IShipSpeedService shipSpeedService;




    @ApiOperation(value = "属性PK")
    @GetMapping("/basicPropertiesPK")
    public AjaxResult basicProperties(PkVo pkvo) {
        SportManBestResultVo sportManBestResultVo = new SportManBestResultVo();
        PkVoList pkVoList = new PkVoList();
        pkVoList.setSportsman(sportsmanService.getById(pkvo.getSportsManIds()));
        pkVoList.setMaps(sportsmanPhysicalQualityService.getSportsmanPhysicalQualityBySportsmanId(pkvo.getSportsManIds(), false));
        sportManBestResultVo.setSportsManId(pkvo.getSportsManIds());
        sportManBestResultVo.setKilometers(pkvo.getKilometers());
        sportManBestResultVo.setClassHour(pkvo.getClassHour());
        sportManBestResultVo.setTrainingMode(pkvo.getTrainingMode());
        sportManBestResultVo.setTrainingProject(pkvo.getType());
        pkVoList.setBestPartnerResultVos(sportsmanService.getBestResultPK(sportManBestResultVo));

        return AjaxResult.success(pkVoList);
    }

    @ApiOperation("运动员端-- 船速仪 -- 教练点击开始按钮")
    @RequestMapping(value = "/start", method = RequestMethod.POST)
    @ResponseBody
    public AjaxResult start(@RequestBody JSONObject jsonObject) {
        return movementService.start(jsonObject);
    }


    @ApiOperation("运动员端-- 船速仪 -- 教练点击结束按钮")
    @RequestMapping(value = "/end", method = RequestMethod.POST)
    @ResponseBody
    public AjaxResult end(@RequestBody JSONObject jsonObject) {
        return movementService.end(jsonObject);
    }


    @ApiOperation("教练员端 -- 查询训练方案")
    @RequestMapping(value = "/getSchemeList", method = RequestMethod.POST)
    public AjaxResult getSchemeList(@RequestBody Scheme scheme) {
        return schemeService.getSchemeList(scheme);
    }


    @ApiOperation("教练员端 -- 查询训练方案，组信息")
    @RequestMapping(value = "/getSchemeDetailsList", method = RequestMethod.POST)
    public AjaxResult getSchemeDetailsList(@RequestBody SchemeDetailsDTO schemeDetailsDTO) {
        return schemeDetailsService.getSchemeDetailsList(schemeDetailsDTO);
    }


    @ApiOperation("教练员端 -- 查询测功仪男女最新排名")
    @RequestMapping(value = "/getDynamometerRanking", method = RequestMethod.POST)
    public AjaxResult getDynamometerRanking(@RequestBody DynamometerRankingDTO dynamometerRankingDTO) {
        return dynamometerService.getDynamometerRanking(dynamometerRankingDTO);
    }


    @ApiOperation("教练员端 -- 手动新增运动员成绩")
    @RequestMapping(value = "/addDynamometer", method = RequestMethod.POST)
    public AjaxResult addDynamometer(@RequestBody JSONObject jsonObject) {
        return dynamometerService.addDynamometer(jsonObject);
    }


    @ApiOperation("教练员端 -- 查询运动员测功仪实时数据")
    @RequestMapping(value = "/getRealTimeData", method = RequestMethod.POST)
    public AjaxResult getRealTimeData(@RequestBody DynamometerRankingDTO dynamometerRankingDTO) {
        return dynamometerService.getRealTimeData(dynamometerRankingDTO);
    }


    @ApiOperation("教练员端 -- 查询运动员测功仪最新一条数据 ，加平均心率和最大心率")
    @RequestMapping(value = "/getLatest", method = RequestMethod.POST)
    public AjaxResult getLatest(@RequestBody DynamometerRankingDTO dynamometerRankingDTO) {
        return dynamometerService.getLatest(dynamometerRankingDTO);
    }


    @ApiOperation("教练员端 -- 新增赛后数据")
    @RequestMapping(value = "/addRaceData", method = RequestMethod.POST)
    public AjaxResult addRaceData(@RequestBody JSONObject jsonObject) {
        return raceDataService.addRaceData(jsonObject);
    }


    @ApiOperation("教练员端 -- 查询赛后数据")
    @RequestMapping(value = "/getRaceData", method = RequestMethod.POST)
    public AjaxResult getRaceData(@RequestBody RaceData raceData) {
        return raceDataService.getRaceData(raceData);
    }


    @ApiOperation("教练员端 -- 查询所有船速仪列表")
    @RequestMapping(value = "/getShipSpeed", method = RequestMethod.POST)
    public AjaxResult getShipSpeed(@RequestBody ShipSpeed shipSpeed) {
        return shipSpeedService.getShipSpeed(shipSpeed);
    }










}
